package com.freeman.cement.controller;

import com.freeman.cement.annotation.NeedRole;
import com.freeman.cement.entity.Dept;
import com.freeman.cement.entity.ResponseResult;
import com.freeman.cement.service.DeptService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//工段管理
//这里的工段等同于部门
@RestController
@RequestMapping("/dept")
@CrossOrigin    //允许跨域访问
public class DeptController
{
    @Resource
    private DeptService service;

    /**
     * 查询工段详细信息
     * @param id
     * @return
     */
    @RequestMapping(value = "/findDept", method = RequestMethod.POST)
    public ResponseResult findDept(@RequestParam("id") int id){
        return service.getDept(id);
    }

    /**
     * 分页查询工段列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/selectAllDeptByPage", method = RequestMethod.POST)
    public ResponseResult selectAllDeptByPage(@RequestParam int pageNo, @RequestParam int pageSize){
        return service.selectAllDept(pageNo, pageSize);
    }

    /**
     * 新增工段/部门
     * @param dept
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/addDept", method = RequestMethod.POST)
    public ResponseResult addDept(Dept dept){
        dept.setIsDutyRoom(0);
        return service.addDept(dept);
    }

    /**
     * 删除工段/部门
     * @param id
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/deleteDept", method = RequestMethod.POST)
    public ResponseResult deleteDept(@RequestParam("id") int id) {
        return service.deleteDept(id);
    }

    /**
     * 编辑工段/部门
     * @param dept
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/updateDept", method = RequestMethod.POST)
    public ResponseResult updateDept(Dept dept){
        return service.updateDept(dept);
    }

}
